package com.bolingcavalry.uschedule;

import com.winit.schedule.core.model.AssignedTask;
import com.winit.schedule.core.model.JobID;
import com.winit.schedule.core.model.TaskID;
import com.winit.schedule.core.repository.constants.AlarmStrategy;
import com.winit.schedule.core.repository.constants.AlarmType;
import com.winit.schedule.core.repository.constants.TaskItemStatus;
import com.winit.schedule.core.repository.constants.TaskStatus;
import com.winit.schedule.core.repository.entity.TaskItemEntity;
import com.winit.schedule.core.task.ScheduleTaskDefine;
import com.winit.schedule.core.task.TaskInterfaceType;
import com.winit.schedule.task.tracker.TaskTracker;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/")
public class Controller {
    @RequestMapping("/test")
    @ResponseBody
    public void test(){
        List<AssignedTask> tasks = new ArrayList<AssignedTask>();
        AssignedTask task = new AssignedTask();

        ScheduleTaskDefine taskDefine = new ScheduleTaskDefine();
        taskDefine.setGroup("matrix");
        taskDefine.setTaskName("MatrixTest");
        taskDefine.setTaskDealClass("com.bolingcavalry.uschedule.MatrixSchedule");
        taskDefine.setInterfaceType(TaskInterfaceType.SCHEDULE_TASK_SINGLE);
        taskDefine.setExclude(false);
        task.setTaskDefine(taskDefine);

        List<TaskItemEntity> taskItems = new ArrayList<TaskItemEntity>();
        TaskItemEntity taskItem = new TaskItemEntity();
        TaskID taskId = new TaskID();
        taskId.setTaskId("matrix$MatrixTest");
        JobID jobID = new JobID();
        jobID.setJobId("20180612160915");
        taskId.setJobId(jobID);

        taskItem.setTaskId(taskId);
        taskItem.setTaskItemId("matrix$MatrixTest$$");
        taskItem.setTaskItemStatus(TaskItemStatus.COMPLETE);
        taskItem.setLastFetchTime(1528792842288L);
        taskItem.setLastStatusUpdateTime(1528792832268L);
        taskItem.setLastFetchTaskTrackerUuid("10.130.146.141$matrix$582BD5848C44E76BC9754ECCAF1DC080");
        taskItem.setNextRunTime(1528792850000L);
        taskItem.setAutoRecovery(false);

        taskItems.add(taskItem);
        task.setTaskItems(taskItems);

        task.setPermitRunStartTime(1528792850000L);
        task.setPermitRunEndTime(0);
        task.setAllowTotalFetchNum(1);
        task.setCurrentFetchNum(1);
        task.setTaskId(taskId);
        task.setTaskGroup("matrix");
        task.setInterfaceType(TaskInterfaceType.SCHEDULE_TASK_SINGLE);
//        task.setRunStartTime("0/10 * * * * ?");
        task.setImmediatelyRun(false);
        task.setTaskStatus(TaskStatus.INIT);
        task.setSleepTimeInterval(0);
        task.setBatchDealNum(1);
        task.setAlarmType(AlarmType.EMAIL);
        task.setAlarmTo(null);
        task.setAlarmStrategy(AlarmStrategy.DEFAULT);
        task.setAutoRecovery(false);


        tasks.add(task);

        TaskTracker taskTracker = new TaskTracker();
        taskTracker.reAllocationTask(tasks);
    }
}
